package com.miyake.dsp.osa.lab.wrapper;

import org.apache.commons.lang.ArrayUtils;

import com.miyake.dsp.common.CommonTool;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
import com.miyake.dsp.osa.lab.NoiseDetector2;
@LabUiAnnotation(caption="Auto Noise Detector2")
public class NoiseDetector2Wrapper extends Calculator {
	public static final String INPUT_X = "Input X";
	public static final String INPUT_Y = "Input Y";
	public static final String OUTPUT_NOISE_LEVEL = "Output Noise Y";
	public static final String OUTPUT_NOISE_X = "Output Noise X";	
	
	public NoiseDetector2Wrapper() {
		initInput(INPUT_X);
		initInput(INPUT_Y);
		initOutput(OUTPUT_NOISE_LEVEL);
		initOutput(OUTPUT_NOISE_X);
	}

	
	@Override
	public void process() {
		double[] x = null;
		double[] y = getInput(INPUT_Y).getRealPart();
		
		if (getInput(INPUT_X) == null) {
			x = CommonTool.fillNumber(y.length);
		}
		else {
			x = getInput(INPUT_X).getRealPart();
		}
		
		NoiseDetector2 noiseDetector = new NoiseDetector2(y);
		setOutput(OUTPUT_NOISE_LEVEL, ArrayUtils.toPrimitive(noiseDetector.getCandicates().toArray(new Double[0])));
		double[] noiseX = new  double[noiseDetector.getIndexCandicates().size()];
		int i = 0;
		for (Integer index : noiseDetector.getIndexCandicates()) {
			noiseX[i++] = x[index];
		}
		setOutput(OUTPUT_NOISE_X, noiseX);
	}

	@Override
	public Object getSetting() {
		// TODO Auto-generated method stub
		return null;
	}

}
